package com.zsj.juc.pool;

import java.util.concurrent.*;

/**
 * @author zsj
 * @version 1.0
 * @date 2024/4/21 17:02
 * @description
 */
public class ThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        ExecutorService threadPool2 = Executors.newSingleThreadExecutor();
        ExecutorService threadPool3 = Executors.newCachedThreadPool();
        /*
        线程池七个参数 ThreadPoolExecutor
        int corePoolSize  常驻线程数量(核心)
        int maximumPoolSize 最大线程数量
        long keepAliveTime 线程存活时间
        TimeUnit unit 存活时间单位
        BlockingQueue<Runnable> workQueue  阻塞队列
        ThreadFactory threadFactory  线程工厂
        RejectedExecutionHandler handler 拒绝策略
            AbortPolicy 直接抛出异常 默认策略
            CallerRunsPolicy 用调用者所在的线程来执行任务
            DiscardPolicy 丢弃任务
            DiscardOldestPolicy 丢弃阻塞队列最靠前的任务 并执行当前任务
         */
        ArrayBlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(3);

        new ThreadPoolExecutor(5, 7, 0, TimeUnit.MILLISECONDS, blockingQueue,
                r -> new Thread(r, "zsj"),
                new ThreadPoolExecutor.CallerRunsPolicy());

    }
}
